package com.example.shop_2305.search

import androidx.lifecycle.viewModelScope
import com.example.lib_base.entity.GoodsEntity
import com.example.lib_base.entity.Res
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.net.SingleLiveData
import kotlinx.coroutines.launch
import retrofit2.http.Query

class SearchViewModel:BaseViewModel() {
    //请求商品
    val goodsSuccess = SingleLiveData<Res<GoodsEntity>>()
    val goodsFail = SingleLiveData<String>()
    fun goods(cid:Int,
              keyword:String,
              limit:Int,
              news:Boolean,
              page:Int,
              priceOrder:String,
              salesOrder:String){
        viewModelScope.launch {
            try {
                goodsSuccess.postValue(apiService.goods(cid, keyword, limit, news, page, priceOrder, salesOrder))
            } catch (e: Exception) {
                goodsFail.postValue(e.message.toString())
            }
        }
    }
}